const fs = require('fs');
const path = require('path');

// Set the directory path to process
const dirPath = './input/game/'; // Change this to your desired directory path


// Recursive function to process files and directories
function traverseDir(dirPath, callback) {
  
    fs.readdir(dirPath, (err, files) => {
      if (err) {
        console.error(err);
        return;
      }
      files.forEach((file) => {
        const filePath = path.join(dirPath, file);
        // Check if the file is a directory
        if (fs.lstatSync(filePath).isDirectory()) {
          // Recursively traverse the subdirectory
          traverseDir(filePath, callback);
        } else {
          // Process the file
          callback(filePath);
        }
      });
    });
  }

// Process all files in the directory and its subdirectories
traverseDir(dirPath, (filePath) => {
    // console.log(`Processing file: ${filePath}`);
    let reg = /\..*\./
    let replace = filePath.replace(reg,".")
    let oldPath = path.join(filePath);
    let newPath =  path.join(replace);
    console.warn("old",oldPath)
    console.warn("replace===>",newPath)
    fs.rename(oldPath,newPath,(err)=>{
        console.warn("err",err)
    })
    // fs.rename()
    // Add your custom processing logic here
    // // For example:
    // const contents = fs.readFileSync(filePath, 'utf8');
    // console.log(contents);
  });